//
//  MLTabBar.m
//  MLSina20160625_Objective-C
//
//  Created by manmanlang on 16/6/25.
//  Copyright © 2016年 manmanlang. All rights reserved.
//

#import "MLTabBar.h"
#import "MLButton.h"

@implementation MLTabBar

- (void)layoutSubviews {
    
    [self setupButton];
}

- (void)setupButton {
    
//    self.backgroundColor = [UIColor whiteColor];
    
    CGFloat buttonW = [UIScreen mainScreen].bounds.size.width * 0.2;
    
    NSArray *barBarTitleArray = @[
                                  @"首页",
                                  @"消息",
                                  @"",
                                  @"发现",
                                  @"我"
                                  ];
    NSArray *barBarImageArray = @[
                                  @"home",
                                  @"message_center",
                                  @"",
                                  @"discover",
                                  @"profile"
                                  ];
    
    
    
    for (int i = 0; i < 5; i ++) {
        
        
        
        if (i == 2) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            
            button.frame = CGRectMake(i * buttonW, 0, buttonW, self.bounds.size.height);
            [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
            [button setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
            [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
            [self addSubview:button];
        }else {
            
            MLButton *button = [[MLButton alloc] init];
            [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            button.frame = CGRectMake(i * buttonW, 0, buttonW, self.bounds.size.height);
            [button setTitle:barBarTitleArray[i] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tabbar_%@",barBarImageArray[i]]] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tabbar_%@_highlighted",barBarImageArray[i]]] forState:UIControlStateHighlighted];
            [self addSubview:button];
        }
        
        
    }
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
